﻿@using Easy.CMS.Common.Models
@using Easy.HTML.jsTree
@{

}
<div class="panel panel-default">
    <div class="panel-heading">
        <span class="badge">导航</span>
        <a href="@Url.Action("Create", new { ParentID ="#"})" class="btn btn-primary btn-xs">
            <i class="glyphicon glyphicon-plus"></i>
            添加导航
        </a>
    </div>
    <div class="panel-body">

        @(
 Html.Tree<NavigationEntity>().Source("GetPageTree", "Navigation", new { module = "Common" })
 .AddPlugin(Plugins.ContextMenu)
 .AddPlugin(Plugins.DragAndDrop)
 .CheckCallBack("checkCallBack")
 .AddContextMenuItem(new ContextmenuItem { Label = "新建", Action = "Create" })
 .AddContextMenuItem(new ContextmenuItem { Label = "编辑", Action = "Edit" })
 .On(Events.MoveNode, "moveNode")
        )

    </div>
</div>
<script type="text/javascript">
    function Create(node) {
        var parent = node.reference.attr("id");
        window.location.href = '@Url.Action("Create", "Navigation", new { module = "Common" })' + '?ParentID=' + parent;
    }
    function Edit(node) {
        var id = node.reference.attr("id");
        window.location.href = '@Url.Action("Edit", "Navigation", new { module = "Common" })' + '?ID=' + id;
    }
    function checkCallBack(operation, node, node_parent, node_position, more) {
        return true;
    }
    function moveNode(node, parent) {
        $.post("@Url.Action("MovePage")", { id: parent.node.id, parentId: parent.parent, position: parent.position + 1, oldPosition: parent.old_position + 1 }, function () {

        }, "json");
    }
</script>
